#include "StdAfx.h"
#include "ConsoleObject.h"
#include "CCommandDictionary.h"
#include "CCommandVariable.h"
#include "CCommandAlias.h"
#include "CCommandFunction.h"

CCommandDictionary & GetConsleDictionary()
{
	static CCommandDictionary dic;
	return dic;
}


SConsFunc::SConsFunc( const csString & strName, FuncExecCallback *pFunc, 
					 const csString & strHelp /*= "unknown command." */ ) 
{
	CCommand *pCommand = new CCommandFunction( strName, pFunc, strHelp );
	GetConsleDictionary().AddCommand( strName, pCommand );
}


SConsVar::SConsVar( const std::string & strName, IValue & rValue, 
					 const std::string & strHelp /*= "unknown command." */ ) 
{
	CCommand *pCommand = new CConsoleVariable( strName, rValue, strHelp );
	GetConsleDictionary().AddCommand( strName, pCommand );
}


SConsAlias::SConsAlias( const csString & strAliasName, const csString & strCommandName )
{
	CCommand *pOriginCommand = GetConsleDictionary().GetCommand( strCommandName );
	CCommand *pCommand = new CCommandAlias( strAliasName, pOriginCommand );
	GetConsleDictionary().AddCommand( strAliasName, pCommand );
}
